<?php

namespace app\admin\controller\kefu;

use app\common\controller\Backend;
use modules\kefu\library\StrComparison;

/**
 * 知识库管理
 */
class Kbs extends Backend
{
    /**
     * Kbs模型对象
     * @var object
     * @phpstan-var \app\admin\model\kefu\Kbs
     */
    protected object $model;

    protected string|array $defaultSortField = 'weigh,desc';

    protected array|string $preExcludeFields = ['id', 'create_time'];

    protected string|array $quickSearchField = ['id', 'problem'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new \app\admin\model\kefu\Kbs;
        $this->request->filter('clean_xss');
    }

    public function match(): void
    {
        $text1 = $this->request->param('text1', '');
        $text2 = $this->request->param('text2', '');

        if (!$text1 || !$text2) {
            $this->error('参数错误！');
        }

        $StrComparison = new StrComparison();
        $match         = $StrComparison->getSimilar($text1, $text2);

        $this->success('', [
            'match' => $match
        ]);
    }
}